<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xml:lang="en" lang="en">
	<h:head />
	<body>
		<ui:composition template="/rootWeb.xhtml">
	    <ui:define name="header">
	        <title>系统帐户管理</title>
	        <script type="text/javascript">
				//页面载入时注册
	        	jQuery(document).ready(function(){
	        		//鼠标移入
					jQuery("#systemAccountTable_data tr").live("mouseover", function() {
					  	jQuery(this).css("background-color","#CCCCCC");
					});
					//鼠标移出
					jQuery("#systemAccountTable_data tr").live("mouseout", function() {
					  	jQuery(this).css("background-color","white");
					});
				});
			</script>
			<style type="text/css">
				
			</style>
		</ui:define>
	    <ui:define name="body">
	    	<h:form id="form" prependId="false">
				<p:dataTable id="accountTable" value="#{systemAccountAction.sysAccountList}" var="account" rowKey="#{account}" emptyMessage="没有记录！"
	    				paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
               			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
               			<f:facet name="header">系统用户列表</f:facet>
               			<p:column headerText="用户名称">#{account.accountName}</p:column>
               			<p:column headerText="用户密码">#{account.accountPassword}</p:column>
               			<p:column headerText="用户类型">
               				<h:outputText value="客户" rendered="#{account.accountType eq 'CUSTOMER'}" />
               				<h:outputText value="岗位" rendered="#{account.accountType eq 'POST'}" />
               				<h:outputText value="机台" rendered="#{account.accountType eq 'MACHINE'}" />
               			</p:column>
               			<p:column headerText="创建时间">
               				<h:outputText value="#{account.createDate}" >
               					<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
               				</h:outputText>
               			</p:column>
               			<p:column headerText="角色名称" >
               			    <h:outputText value="#{account.machine.machineNumber}" rendered="#{account.accountType eq 'MACHINE'}"  />
               			    <h:outputText value="#{account.customer.customerName}" rendered="#{account.accountType eq 'CUSTOMER'}"  />
               				<h:outputText value="#{account.post.postName}" rendered="#{account.accountType eq 'POST'}"  />
               			</p:column>
               			<p:column headerText="默认路径" >
               				<h:outputText value="#{account.defaultPath}" />
               			</p:column>
               			<p:column headerText="用户状态" >
               				<h:selectOneMenu id="accountAvailable" value="#{account.available}" disabled="true" style="width:80px">  
				                <f:selectItems value="#{systemAccountAction.availableItems}"/>
				            </h:selectOneMenu>
               			</p:column>
               			<p:column headerText="操作">
			    			<p:commandLink value="修改"  action="#{systemAccountAction.setUpdateAccount(account)}" update=":form:updateAccountDlgID"  oncomplete="updateAccountDlg.show()" style="margin-right:5px;color:RED"/>
			    			<p:commandLink value="禁用"  action="#{systemAccountAction.setUpdateAccount(account)}" update=":form:updateAccountDlgID"  oncomplete="forbiddenAccountDlg.show()" style="margin-right:5px;color:RED"/>
			    		</p:column>
			    		<f:facet name="footer">
							<p:commandButton value="新增" action="#{systemAccountAction.addAccount}" update=":form:addAccountDlgID" oncomplete="addAccountDlg.show()"/>
						</f:facet>
               	</p:dataTable>
               	
               	<!-- 禁用 -->
				<p:confirmDialog id="forbiddenAccountDlgID" message="确认禁用用户吗?"
					header="禁用用户" severity="alert" widgetVar="forbiddenAccountDlg">
					<p:commandButton value="确定" update=":form:accountTable" action="#{systemAccountAction.forbiddenAccount}"
						oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);forbiddenAccountDlg.hide();}"  />
					<p:commandButton value="取消" onclick="forbiddenAccountDlg.hide()" type="button" />
				</p:confirmDialog>
               	<!--  新增 -->
               	<p:dialog id="addAccountDlgID" header="新增用户" widgetVar="addAccountDlg" modal="true" resizable="false" >
					<p:outputPanel style="width: 100%" >
						<h:panelGrid columns="2">
						    <h:panelGrid columns="2">
							    <h:outputLabel for="addAccountName" value="用户名称："/>
							    <p:inputText id="addAccountName" value="#{systemAccountAction.addAccount.accountName}" />
							</h:panelGrid>  
							<h:panelGrid columns="2"> 
							    <h:outputLabel for="addAccountPassword" value="用户密码："/>
							    <p:inputText id="addAccountPassword" value="#{systemAccountAction.addAccount.accountPassword}" />
				            </h:panelGrid>
				            <h:panelGrid columns="2"> 
				                <h:outputLabel for="addAccountType" value="用户类型："/>
               				    <h:selectOneMenu id="addAccountType" value="#{systemAccountAction.addAccount.accountType}" disabled="false" style="width:120px">  
				                    <f:selectItems value="#{systemAccountAction.accountTypeItems}"/>
				                </h:selectOneMenu>
               			    </h:panelGrid>
               			    <h:panelGrid columns="3">
               			        <h:outputLabel for="addAccountCustomer" value="客户："/>
						        <p:inputText value="#{systemAccountAction.addAccount.customer.customerName}" id="addAccountCustomer" readonly="true" style="width: 160px;font-weight: bold" />
						        <p:commandLink  value="选择" action="#{systemAccountAction.findAllCustomers('add')}" 
							     style="color:RED"
							     oncomplete="selectCustomerDlg.show();"
							     update=":form:customerTable">
							    </p:commandLink>
							</h:panelGrid>
							<h:panelGrid columns="3">
               			        <h:outputLabel for="addAccountPost" value="岗位："/>
						        <p:inputText value="#{systemAccountAction.addAccount.post.postName}" id="addAccountPost" readonly="true" style="width: 160px;font-weight: bold" />
						        <p:commandLink  value="选择" action="#{systemAccountAction.findAllPosts('add')}" 
							     style="color:RED"
							     oncomplete="selectPostDlg.show();"
							     update=":form:postTable">
							    </p:commandLink>
							</h:panelGrid>
							<h:panelGrid columns="3">
               			       <h:outputLabel for="addAccountMachine" value="机台："/>
						       <p:inputText value="#{systemAccountAction.addAccount.machine.machineNumber}" id="addAccountMachine" readonly="true" style="width: 160px;font-weight: bold" />
						       <p:commandLink  value="选择" action="#{systemAccountAction.findAllMachines('add')}" 
							    style="color:RED"
							    oncomplete="selectMachineDlg.show();"
							    update=":form:machineTable">
							   </p:commandLink>
							</h:panelGrid>
							<h:panelGrid columns="2">
							   <h:outputLabel for="addAccountDefaultPath" value="登录路径："/>
               				   <h:selectOneMenu id="addAccountDefaultPath" value="#{systemAccountAction.addAccount.defaultPath}" disabled="false" style="width:120px">  
				                   <f:selectItems value="#{systemAccountAction.defaultPathItems}"/>
				               </h:selectOneMenu>
               			    </h:panelGrid>
               			    <h:panelGrid columns="2">
				                <h:outputLabel for="addAccountAvailable" value="是否禁用："/>
               				    <h:selectOneMenu id="addAccountAvailable" value="#{systemAccountAction.addAccount.available}" disabled="false" style="width:120px">  
				                    <f:selectItems value="#{systemAccountAction.availableItems}"/>
				                </h:selectOneMenu>
               			    </h:panelGrid>
						</h:panelGrid>
					</p:outputPanel>
					<f:facet name="footer">
						<p:commandButton value="保存" update=":form:accountTable" action="#{systemAccountAction.addAccount}"
							oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);addAccountDlg.hide();}"  />
					</f:facet>
				</p:dialog>
				<!-- 更新 -->
				<p:dialog id="updateAccountDlgID" header="修改用户" widgetVar="updateAccountDlg" modal="true" resizable="false" >
					<p:outputPanel style="width: 100%" >
						<h:panelGrid columns="2">
						    <h:panelGrid columns="2">
							    <h:outputLabel for="updateAccountName" value="用户名称："/>
							    <p:inputText id="updateAccountName" value="#{systemAccountAction.updateAccount.accountName}" />
				            </h:panelGrid>
				            <h:panelGrid columns="2">
				                <h:outputLabel for="updateAccountPassword" value="用户密码："/>
							    <p:inputText id="updateAccountPassword" value="#{systemAccountAction.updateAccount.accountPassword}" />
							</h:panelGrid>
							<h:panelGrid columns="2">
							    <h:outputLabel for="updateAccountType" value="用户类型："/>
               				    <h:selectOneMenu id="updateAccountType" value="#{systemAccountAction.updateAccount.accountType}" disabled="false" style="width:120px">  
				                    <f:selectItems value="#{systemAccountAction.accountTypeItems}"/>
				                </h:selectOneMenu>
               			    </h:panelGrid>
               			    <h:panelGrid columns="3">
               			        <h:outputLabel for="updateAccountCustomer" value="客户："/>
						        <p:inputText value="#{systemAccountAction.updateAccount.customer.customerName}" id="updateAccountCustomer" readonly="true" style="width: 160px;font-weight: bold" />
						        <p:commandLink  value="选择" action="#{systemAccountAction.findAllCustomers('update')}" 
							    style="color:RED"
							    oncomplete="selectCustomerDlg.show();"
							    update=":form:customerTable">
							    </p:commandLink>
							</h:panelGrid>
							<h:panelGrid columns="3">
               			        <h:outputLabel for="updateAccountPost" value="岗位："/>
						        <p:inputText value="#{systemAccountAction.updateAccount.post.postName}" id="updateAccountPost" readonly="true" style="width: 160px;font-weight: bold" />
						        <p:commandLink  value="选择" action="#{systemAccountAction.findAllPosts('update')}" 
							    style="color:RED"
							    oncomplete="selectPostDlg.show();"
							    update=":form:postTable">
							    </p:commandLink>
							</h:panelGrid>
							<h:panelGrid columns="3">
               			        <h:outputLabel for="updateAccountMachine" value="机台："/>
						        <p:inputText value="#{systemAccountAction.updateAccount.machine.machineNumber}" id="updateAccountMachine" readonly="true" style="width: 160px;font-weight: bold" />
						        <p:commandLink  value="选择" action="#{systemAccountAction.findAllMachines('update')}" 
							    style="color:RED"
							    oncomplete="selectMachineDlg.show();"
							    update=":form:machineTable">
							    </p:commandLink>
							</h:panelGrid>
							<h:panelGrid columns="2">
							    <h:outputLabel for="updateAccountDefaultPath" value="默认路径："/>
               				    <h:selectOneMenu id="updateAccountDefaultPath" value="#{systemAccountAction.updateAccount.defaultPath}" disabled="false" style="width:120px">  
				                    <f:selectItems value="#{systemAccountAction.defaultPathItems}"/>
				                </h:selectOneMenu>
               			    </h:panelGrid>
               			    <h:panelGrid columns="2">
				                <h:outputLabel for="updateAccountAvailable" value="是否禁用："/>
               				    <h:selectOneMenu id="updateAccountAvailable" value="#{systemAccountAction.updateAccount.available}" disabled="false" style="width:120px">  
				                    <f:selectItems value="#{systemAccountAction.availableItems}"/>
				                </h:selectOneMenu>
               			    </h:panelGrid>
						</h:panelGrid>
					</p:outputPanel>
					<f:facet name="footer">
						<p:commandButton value="更新" update=":form:accountTable" action="#{systemAccountAction.updateAccount}"
							oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);updateAccountDlg.hide();}"  />
					</f:facet>
				</p:dialog>
				<p:dialog id="selectCustomerDlgID" header="选择客户" widgetVar="selectCustomerDlg" modal="true"  resizable="false">
		            <h:panelGrid  columns="2" cellpadding="5">
			            <p:dataTable id="customerTable" value="#{systemAccountAction.customerList}" var="customer" rowKey="#{customer}" emptyMessage="没有记录！"
					         selection="#{systemAccountAction.selectedCustomer}"
				             paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="true" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
		                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  >
		                    <p:column selectionMode="single" ></p:column>
			                <p:column headerText="客户编号">#{customer.customerCode}</p:column>
			                <p:column headerText="客户名称">#{customer.customerName}</p:column>
			                <p:column headerText="客户地区">#{customer.customerRegion}</p:column>
			            </p:dataTable>
			            <f:facet name="footer">
			                <p:commandButton value="确定" action="#{systemAccountAction.doSelectCustomer()}" oncomplete="selectCustomerDlg.hide()"
			    	           update=":form:addAccountCustomer,:form:updateAccountCustomer"/>
			            </f:facet>
		            </h:panelGrid>
		         </p:dialog>
		         <p:dialog id="selectPostDlgID" header="选择岗位" widgetVar="selectPostDlg" modal="true"  resizable="false">
		            <h:panelGrid  columns="2" cellpadding="5">
			            <p:dataTable id="postTable" value="#{systemAccountAction.postList}" var="post" rowKey="#{post}" emptyMessage="没有记录！"
					         selection="#{systemAccountAction.selectedPost}"
				             paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="true" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
		                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  >
		                    <p:column selectionMode="single" ></p:column>
			                <p:column headerText="岗位编号">#{post.postCode}</p:column>
			                <p:column headerText="岗位名称">#{post.postName}</p:column>
			                <p:column headerText="岗位描述">#{post.postDesc}</p:column>
			            </p:dataTable>
			            <f:facet name="footer">
			                <p:commandButton value="确定" action="#{systemAccountAction.doSelectPost()}" oncomplete="selectPostDlg.hide()"
			    	           update=":form:addAccountPost,:form:updateAccountPost"/>
			            </f:facet>
		            </h:panelGrid>
		         </p:dialog>
		          <p:dialog id="selectMachineDlgID" header="选择机台" widgetVar="selectMachineDlg" modal="true"  resizable="false">
		            <h:panelGrid  columns="2" cellpadding="5">
			            <p:dataTable id="machineTable" value="#{systemAccountAction.machineList}" var="machine" rowKey="#{machine}" emptyMessage="没有记录！"
					         selection="#{systemAccountAction.selectedMachine}"
				             paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="true" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
		                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  >
		                    <p:column selectionMode="single" ></p:column>
			                <p:column headerText="机台编号">#{machine.machineNumber}</p:column>
			                <p:column headerText="机台描述">#{machine.machineRemark}</p:column>
			            </p:dataTable>
			            <f:facet name="footer">
			                <p:commandButton value="确定" action="#{systemAccountAction.doSelectMachine()}" oncomplete="selectMachineDlg.hide()"
			    	           update=":form:addAccountMachine,:form:updateAccountMachine"/>
			            </f:facet>
		            </h:panelGrid>
		         </p:dialog>
			</h:form>
	    </ui:define>
		</ui:composition>
	</body>
</html>
